// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html


import gameData from "../../resources/scripts/gameData";
import sceneMediator from "../../resources/framework/sceneMediator";
import GameConfig from "../../resources/framework/GameConfig";
import languageManager from "../../resources/scripts/languageManager/languageManager";
import AudioManage from "../../resources/framework/AudioManage";

const {ccclass, property} = cc._decorator;

@ccclass
export default class loadingMediator extends cc.Component {

    @property(cc.ProgressBar)
    progressBar : cc.ProgressBar = null;

    audioProgress = 0;

    protected onLoad(): void {
        let promises = [];

        promises.push(new Promise((resolve, reject) => {

            let action = ()=>{

                AudioManage.init();
                //获取特殊关卡数据
                sceneMediator.getLocalSpecialLevelInformation();
                //获取普通关卡历史最高关卡
                sceneMediator.getLocalHighestLevelInformation();
                //获取普通关卡上次进入游戏的关卡
                sceneMediator.getLocalNormalLevelInformation();
                //json数据文件的解析
                gameData.analysisLocalJsonInformation();
                //获取各关卡苹果数
                gameData.getLocalEveryLevelAppleInformation();
                //获取已获得总苹果数
                gameData.getLocalTotalAppleInformation();
                //初始化国家语言
                languageManager.initCityInformation();
            };

            action();

            resolve();
        }));

        Promise.all(promises).then(()=>{
            cc.director.loadScene("main",()=>{

            });
        });
    }

    isOver = false;
    protected update(dt: number): void {
        this.audioProgress += 0.02;
        if(this.audioProgress >= 1) {
            this.audioProgress = 1;
        }
        this.progressBar.progress = this.audioProgress;
    }

}
